<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>addclassTable</title>
    <link rel="icon" th:href="@{/images/logo.png}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/themes/default.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body {
            padding: 20px;
        }
    </style>
</head>
<body>

<form class="layui-form layui-form-pane" >
    <div class="layui-form-item">
        <label class="layui-form-label">课程编号:</label>
        <div class="layui-input-block">
            <input type="text" required lay-verify="required|number"  placeholder="id" name="classId"
                   class="layui-input layui-input-dis">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">课程名称：</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入要添加的课程名称" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">时长:</label>
        <div class="layui-input-block">
            <input type="text" name="classBegin" required lay-verify="required" placeholder="时长" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">课程时间:</label>
        <div class="layui-input-block">
            <input type="text" name="classTime" required lay-verify="required" placeholder="请输入正确的时间" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">教练:</label>
        <div class="layui-input-block">
            <input type="text" name="coach" required lay-verify="required" placeholder="" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn-submit" class="layui-btn" lay-submit lay-filter="btn-submit-filter">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>


<script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}" charset="utf-8"></script>
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/jq-module/jquery.particleground.min.js}" charset="utf-8"></script>
<script th:inline="javascript">
     var ctxPath= [[@{/}]];
        //日期设置
        layui.use(['laydate', 'table','form'] , function () {
            var table = layui.table;
            var form = layui.form;
            var $ =layui.$;
            form.on('submit(btn-submit-filter)', function(data){     //将登录按钮置灰不可用
                $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");
                //异步请求提交数据
                // 提交成功则关闭窗口，并且刷新数据表格
                //失败则提示错误信息，窗口不关闭
                var url = ctxPath+"class";
                $.post(url,data.field,function(response){

                    if(response.code==0){
                        layer.msg(response.message,{icon:6,time:2000}, function () {
                            //刷新表格
                            parent.refreshTable();
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭

                        });
                    }
                    else {
                        $("#btn-submit").removeAttr("disabled", "disabled").removeClass("layui-btn-disabled");
                        layer.msg("新增失败请联系管理员",{icon:5,anim:6});
                    }

                });
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });

        });

</script>
</body>
</html>